package sprite;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import spritebehavior.Behavior;


/**
 * @author Seon Kang
 * edited by Guy Tracy
 * 
 */
public class Sprite {
    private int myID;
    private Image myImage;
    private Behavior mySpriteBehavior;
    private String myName;
    private Point myCenter;
    private Point myVelocity;
    private Dimension mySize;
    private double myAngle;
    private double myAngularVelocity;

    /**
     * 
     * @param concreteBehavior
     * @param img
     * @param center
     * @param velocity
     * @param size
     * @param angle
     * @param angularvelocity
     */
    public Sprite (int spriteID, Behavior concreteBehavior, Image img, Point center,
            Point velocity, Dimension size, double angle, double angularvelocity) {
        setSpriteID(spriteID);
        setBehavior(concreteBehavior);
        setImage(img);
        setCenter(center);
        setVelocity(velocity);
        setAngle(angle);
        setAngularVelocity(angularvelocity);
        setSize(size);
    }

    /**
     * @param spriteID
     */
    public void setSpriteID (int spriteID) {
        myID = spriteID;
    }
    
    public int getSpriteID () {
        return myID;
    }

    /**
     * @param dt delta t
     */
    public void update () {
        mySpriteBehavior.update();
    }

    protected void paint (Graphics pen) {
        pen.drawImage(getImage(), getCenter().x - getSize().width / 2,
                getCenter().y - getSize().height / 2, null);
    }

    /**
     * 
     * @param location
     */
    public void setCenter (Point location) {
        myCenter = location;
    }

    /**
     * @return the center of the sprites
     * 
     */
    public Point getCenter () {
        return myCenter;
    }

    protected void setBehavior (Behavior concreteBehavior) {
        mySpriteBehavior = concreteBehavior;
    }

    /**
     * @return return the Behavior of this sprite.
     */
    public Behavior getBehavior () {
        return mySpriteBehavior;
    }

    protected void setImage (Image img) {
        myImage = img;
    }

    protected Image getImage () {
        return myImage;
    }

    protected void setName (String name) {
        myName = name;
    }

    protected String getName () {
        return myName;
    }

    /**
     * 
     * @return
     */
    public Point getVelocity () {
        return myVelocity;
    }

    /**
     * 
     * @param velocity
     */
    public void setVelocity (Point velocity) {
        this.myVelocity = velocity;
    }

    /**
     * 
     * @return
     */
    public double getAngle () {
        return myAngle;
    }

    /**
     * 
     * @param angle
     */
    public void setAngle (double angle) {
        this.myAngle = angle;
    }

    public double getAngularVelocity () {
        return myAngularVelocity;
    }

    public void setAngularVelocity (double angular) {
        this.myAngularVelocity = angular;
    }

    public Dimension getSize () {
        return mySize;
    }

    public void setSize (Dimension mySize) {
        this.mySize = mySize;
    }

    /**
     * Returns shape's left-most coordinate.
     */
    public int getLeft () {
        return getCenter().x - getSize().width / 2;
    }

    /**
     * Returns shape's top-most coordinate.
     */
    public int getTop () {
        return getCenter().y - getSize().height / 2;
    }

    /**
     * Returns shape's right-most coordinate.
     */
    public int getRight () {
        return getCenter().x + getSize().width / 2;
    }

    /**
     * Reports shape's bottom-most coordinate.
     * 
     * @return bottom-most coordinate
     */
    public int getBottom () {
        return getCenter().y + getSize().height / 2;
    }

    /**
     * @author Robert Duvall
     * 
     *         Returns true if the given point is within a rectangle
     *         representing this shape.
     * @param pt
     */
    public boolean intersects (Point pt) {
        return getLeft() <= pt.x && pt.x <= getRight() && getTop() <= pt.y
                && pt.y <= getBottom();
    }

    /**
     * @return the behavior class of this sprite.
     */
    public Class<? extends Behavior> getType () {
        return mySpriteBehavior.getClass();
    }
}
